//
//  UIView+FPUIView_Extention.m
//  FilmParadise
//
//  Created by YangYujie on 15/7/13.
//  Copyright (c) 2015年 DLYgroup. All rights reserved.
//

#import "UIView+FPUIView_Extention.h"

@implementation UIView (FPUIView_Extention)
- (void)setX:(CGFloat)x
{
    CGRect frame = self.frame;
    frame.origin.x = x;
    self.frame = frame;
}
- (void)setY:(CGFloat)y
{
    CGRect frame = self.frame;
    frame.origin.y = y;
    self.frame = frame;
}
- (CGFloat)x
{
    return self.frame.origin.x;
}
- (CGFloat)y
{
    return self.frame.origin.y;
}
- (void)setWidth:(CGFloat)width
{
    CGRect frame = self.frame;
    frame.size.width = width;
    self.frame = frame;
}
- (void)setHeight:(CGFloat)height
{
    CGRect frame = self.frame;
    frame.size.height = height;
    self.frame = frame;
}
- (CGFloat)width
{
    return self.frame.size.width;
}
- (CGFloat)height
{
    return self.frame.size.height;
}
- (void)setSize:(CGSize)size
{
    CGRect frame = self.frame;
    frame.size = size;
    self.frame = frame;
}
- (CGSize)size
{
    return self.frame.size;
}
- (void)setOrigin:(CGPoint)origin
{
    CGRect frame = self.frame;
    frame.origin = origin;
    self.frame = frame;
}
- (CGPoint)origin
{
    return self.frame.origin;
}

// 创建button
+ (UIButton *)buttonWithTarget:(id)target action:(SEL)action image:(NSString *)image highImage:(NSString *)highImage frame:(CGRect)frame
{
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    // 设置图片
    [btn setBackgroundImage:[UIImage imageNamed:image] forState:UIControlStateNormal];
    [btn setBackgroundImage:[UIImage imageNamed:highImage] forState:UIControlStateHighlighted];
    // 设置尺寸
    btn.frame = frame;
    
    return btn ;
}
// 创建标签
+ (UILabel *)labelWithFrame:(CGRect)frame text:(NSString *)text fontSize:(CGFloat)size fontWeight:(CGFloat)weight color:(UIColor *)color
{
    UILabel *label = [[UILabel alloc]initWithFrame:frame];
    label.text = text;
    label.font = [UIFont systemFontOfSize:size weight:weight];
    label.textColor = color;
    return label;
}

// 创建标签 (没有大小)
+ (UILabel *)labelWithFrame:(CGRect)frame text:(NSString *)text color:(UIColor *)color
{
    UILabel *label = [[UILabel alloc]initWithFrame:frame];
    label.text = text;
    label.textColor = color;
    return label;
}

// 创建毛玻璃效果
+ (UIImageView *)buildBlurBackgroundImageView
{
    // 创建一个imageView 他的大小为整个屏幕大小
    UIImageView * backImage = [[UIImageView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    // 给定我们的背景图片
    backImage.image = [UIImage imageNamed:@"bacground.jpg"];
    // 打开用户交互
    backImage.userInteractionEnabled = YES;
    // 我们的磨合效果是覆盖在背景图上面的
    // 所以我们将我们的磨合效果加载到backImage这个ImageView上
    UIVisualEffectView *visualEffectView = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleDark]];
    // 首先要设置下我们visualEffectView这个视图大小
    // 将它设置为backImage一样大
    visualEffectView.frame = backImage.bounds;
    // 给它一个透明度
    visualEffectView.alpha = 0.7;
    // 将visualEffectView添加到backImage上
    [backImage addSubview:visualEffectView];
    
    return backImage;
}
// 创建imageview
+ (UIImageView *)imageViewWithframe:(CGRect)frame imageName:(NSString *)imageName cornerRadius:(CGFloat)cornerRadius bordeWidth:(CGFloat)bordeWidth backgroundColor:(UIColor *)backColor
{
    UIImageView * imageView = [[UIImageView alloc] init];
    imageView.frame =  frame;
    imageView.image = [UIImage imageNamed:imageName];
    imageView.layer.cornerRadius = cornerRadius;
    imageView.layer.masksToBounds = YES;
    imageView.layer.borderColor = backColor.CGColor;
    imageView.layer.borderWidth = bordeWidth;
    return imageView;
}

@end
